import {
    find
} from "@/api/modules/find"

let emptyIndex = 1
let emptyIndexMax = 4
export const getCovers = (list) => {
 /*    const result = list.map((item) => {
        let cover = require(
            `@/assets/images/empty/index0${emptyIndex}.png`)
        emptyIndex = emptyIndex === emptyIndexMax ? 1 : emptyIndex + 1
        return Object.assign(item, {
            cover,
            coverEmpty: true
        })
    })
    return Promise.resolve(result) */
    return new Promise((resolve, reject) => {
        let asyncQueue = []
        list.forEach((item, index) => {
            const asyncItem = find.unify.getPItemAndOnShelfCountAndDuxiuImageUrl({
                title: item.title,
                isbn: item.isbn,
                recordId: item.recordId
            })
                .then(({data}) => {
                    let cover = data.duxiuImageUrl || require(
                        `@/assets/images/empty/index0${emptyIndex}.png`)
                    emptyIndex = emptyIndex === emptyIndexMax ? 1 : emptyIndex + 1
                    return Object.assign(item, {
                        cover,
                        coverEmpty: !data.duxiuImageUrl
                    })
                })
            asyncQueue.push(asyncItem)
        })
        Promise.all(asyncQueue).then((list) => {
            resolve(list)
        })
    })

}